Operating systems and hypervisors that support execution of virtual machines running in computer systems typically employ a page table translation hierarchy to manage mapping of memory from a virtual memory space to a physical memory space that is divided into pages. Each page is a block of contiguous memory addresses, but page sizes may vary between pages. When a page is mapped from an entry of a page table at the lowest level (level 1), the size of the page is the smallest size that is supported by the computer system. When a page is mapped from an entry of a page table at a higher level (level N>1), the size of the page is a larger size that is supported by the computer system. As referred to herein, “small” pages are of a smaller size than “large” pages, but small pages are not necessarily the smallest size that is supported by the computer system. Similarly, large pages are not necessarily the largest size that is supported by the computer system.
To increase the performance of applications running on the virtual machines, computer systems often employ a translation lookaside buffer (TLB) to cache mappings from virtual memory space to physical memory space. Since the size of the TLB is limited, computer systems may further optimize performance by using large pages to decrease the likelihood of TLB misses (i.e., mappings that are not stored in the TLB). However, if the available physical memory becomes scarce, then unused portions of the large pages unnecessarily waste memory and may lead to performance degradation.
In an attempt to reduce performance degradation, some hypervisors randomly select large pages for demotion to small pages as the memory becomes scarce. Such an approach allows the hypervisor to reclaim unused portions of the large pages and, thus, reduce memory pressure. However, if one or more applications are actively accessing the selected large page, the time increase required map to small pages instead of large pages may exceed the time decrease attributable to reducing the memory pressure. Consequently, the overall performance of applications may be adversely impacted.